% Function which create connectome
% connectome contains:
% neurons - the array of neurons existing in the
%           connectome (recognised by numberOfLayer and numberNeuronInThis
%           layer - as layer no. 0 we treat the input layer (receptors) and
%           as (n+1)th layer we treat the output layer - effectors. This is
%           necessary to ensure connections through the synapse between
%           (input -> connectome) and (connectome -> output)
% synapses - the array of synapses existing in the connectome (identifing
%           by the parameters of two neurons ids - to find proper synapse
%           tou have to define id of neuron A (x_A, y_A) and id of neuron B
%           (x_B, y_B)
% inputSize - size of input vector (size of 0th layer)
% neuronInLayerVector - vector that consists number of nueron in each layer
%                       of connectome.
% outputSize - size of output vector (size of (n+1)th layer)

function [ connectome ] = createConnectome(inputSize, neuronInLayerVector, outputSize)
    % create table of neurons
    % and giving them id and setting the Threshold (for now default value is 1.1)
    counter = 1;
    % Create 0th layer of connectome (receptors)
    for i=1:inputSize
        connectome.neurons(1,counter) = neuron(i,0,0.5);
        counter = counter+1;
    end
    
    numberOfLayers = length(neuronInLayerVector);
    for i=1:numberOfLayers
        for j=1:neuronInLayerVector(i)          
            connectome.neurons(1,counter) = neuron(j,i,0.5);
            counter = counter+1;
        end
    end
    
    % Create (n+1)th layer of connectome (efectors)

    for i=1:outputSize
        connectome.neurons(1,counter) = neuron(i,numberOfLayers+1,0.5);
        counter = counter+1;
    end
    
    % create table of synapses
    % and giving them id and setting them weight (by default 0,5), defined
    % remained time (by default 10).
    counter = 1;
    
    % create synapses between input (receptors) and connectome (0th layer
    % -> 1st layer)
    for i=1:inputSize
        for j=1:neuronInLayerVector(1)
            connectome.synapses(1,counter) = synapse(0.5,1,i,0,j,1, 0, 100, 500, 0);
            counter = counter +1;
        end
    end
    
    % create synapses between all layers in connectome (1st to n-th)
    for i=1:(numberOfLayers-1)
        for j=1:neuronInLayerVector(i)
            for k=1:neuronInLayerVector(i+1)
                connectome.synapses(1,counter) = synapse(0.5,1,j,i,k,i+1, 0, 100, 500, 0);
                counter = counter +1;
            end
        end
    end
     % create synapses between connectome (n-th layer) and output
     % (effectors) (n-th -> (n+1)th layer (output))
    for i=1:neuronInLayerVector(numberOfLayers)
        for j=1:outputSize
            connectome.synapses(1,counter) = synapse(0.5,1,i,numberOfLayers,j,numberOfLayers+1,  0, 100, 500, 0);
            counter = counter +1;
        end
    end
    % assigning the numberOfLayers and numberOfNeuronsInLayer
    connectome.numberOfLayers = numberOfLayers;
    connectome.neuronInLayerVector = neuronInLayerVector;
    connectome.maximalNumberOfNeuronsInLayer = max([neuronInLayerVector inputSize outputSize]);
    connectome.inputSize = inputSize;
    connectome.outputSize = outputSize;
end

